package org.liuqm;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MainTest2 {

    public static void main(String[] args) throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class  clazz=Class.forName("org.liuqm.UserEntity");
        Constructor constructor= clazz.getConstructor();
        //通过无参构造方法进行实例化
        Object o=constructor.newInstance();




        //方法的操作
        Method getUserName=clazz.getMethod("getUserName");

        System.out.println("userNameValue:"+getUserName.invoke(o));
        Method setUserName=clazz.getMethod("setUserName",String.class);
        setUserName.invoke(o,"王五");


        System.out.println("userNameNewValue:"+getUserName.invoke(o));

    }


    /**
     * 创建SysUser 类并对其进行赋值取值的操作
     *
     */


    public void SysUserOp() throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException {
        Class  clazz=Class.forName("org.liuqm.pojo.SysUser");
        Constructor constructor= clazz.getConstructor();
        //通过无参构造方法进行实例化
        Object o=constructor.newInstance();




//        //方法的操作
//        Method getUserName=clazz.getMethod("getUserName");
//
//        System.out.println("userNameValue:"+getUserName.invoke(o));
//        Method setUserName=clazz.getMethod("setUserName",String.class);
//        setUserName.invoke(o,"王五");
//
//
//        System.out.println("userNameNewValue:"+getUserName.invoke(o));
    }



}
